//
// Created by daidai on 2022/12/11.
//

#ifndef AVPLAYER_VIDEOCHANNEL_H
#define AVPLAYER_VIDEOCHANNEL_H


#include <cstdint>
#include "x264.h"
#include "SafeQueue.cpp"
#include "JavaCallHelper.h"
extern "C" {
#include "librtmp/rtmp.h"
}

#include "mylog.cpp"
class VideoChannel {

private:
    int width;
    int height;
    int fps;
    int bitrate;
    char* rtmpUrl{};
    pthread_t __pthread_ptr;
    x264_t *  x264_encoder;
    x264_picture_t* pic_in;//  缓存编码数据的
    uint32_t startTime{};// rtmp 连接好的时间戳
    SafeQueue<RTMPPacket*> *safeQueue;
    JavaCallHelper *javaCallHelper;


public:


    VideoChannel();

    ~VideoChannel();

    int initVideoCodec(int width, int height, int fps, int bitrate);

    void encodeData(int8_t *data);

    void sendSpsPps(uint8_t *sps,uint8_t* pps,int sps_len, int pps_len);

    void setFrame(int type,int payload,const uint8_t *p_payload);

    void sendData(RTMPPacket *packet);

    void startSendData();

    void setStartTime(uint32_t startTime);
    void setRtmpUrl(char* url);
    void setJavaCallHelper( JavaCallHelper *javaCallHelper);
    char*  getRtmpUrl();
    SafeQueue<RTMPPacket*>* getSafeQueue();
};


#endif //AVPLAYER_VIDEOCHANNEL_H
